﻿using System;
using System.IO;
using System.Security;

namespace Exception3
{
    public sealed class PainLess
    {
        /// <summary>
        /// 1. The numeric integer error codes that utterly failed to describe the errors they represented (e.g. what does 2342 mean?) 
        /// 2. The exception classes are not tightly coupled to each other. 
        ///    In contrast, each error integer code must hold a unique value thus coupling all the error codes together. 
        ///    
        /// Nevertheless, you might consider it a reasonable solution if it worked. 
        /// But it doesn't.
        ///     1. TextReader reader = null; must assignment 
        ///     2. the call to reader.Close() could easily throw a NullReferenceException. 
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
                    
        }

        private static void Process(string filename, char[] source)
        {
            throw new NotImplementedException();
        }

        private static char[] ReadSource(string filename)
        {
            TextReader reader = null;
            FileInfo file = new FileInfo(filename);
            int length = (int)file.Length;
            char[] source = new char[length];
            reader = file.OpenText();

            try
            {  
                reader.Read(source, 0, length);
            }
            catch (SecurityException caught) { }
            catch (IOException caught) { }
            catch (OutOfMemoryException caught) { }
            finally
            {
                // drop the null guard inside the finally block 
                if (reader != null)
                {
                    reader.Close();
                }                
            }

            return source;
        }
    }
}
